<?php

use yii\helpers\Html;
use kartik\detail\DetailView;
use backend\models\Country;
use yii\helpers\Url;

/* @var $this yii\web\View */
/* @var $model backend\models\Link */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="container">
    <div class="link-form">
        <?php
        //省市
        $modelCountry = new Country();
        $arr_provinces = $modelCountry->getProvinces();
        $arr_cities = [];
        if ($model->province) {
            $province = implode('', $modelCountry->getProvinces("id =" . $model->province));
            $arr_cities = $modelCountry->getProvinces("pid = $model->province");
        } else {
            $province = '';
        }
        if ($model->city) {
            $city = implode('', $modelCountry->getProvinces("id=" . $model->city));
        } else {
            $city = '';
        }
        $attributes = [
            'title',
            [
                'attribute' => 'category',
                'type' => 'radioList',
                'items' => Yii::$app->params['link_category'],
                'value' => Yii::$app->params['link_category'][$model->category],
                'valueColOptions' => ['class' => 'form-inline'],
            ],
            'url',
            [
                'attribute' => 'desc',
                'type' => DetailView::INPUT_TEXTAREA,
            ],
            [
                'columns' => [
                    [
                        'attribute' => 'province',
                        'type' => DetailView::INPUT_SELECT2,
                        'value' => $province,
                        'widgetOptions' => [
                            'data' => $arr_provinces,
                            'options' => ['placeholder' => '选择省份 ...'],
                            'pluginOptions' => [
                                'allowClear' => true
                            ]
                        ],
//                        'label' => "<span class='text-danger'>" . $model->getAttributeLabel('province') . "*</span>",
                        'valueColOptions' => ['style' => 'width:30%']
                    ],
                    [
                        'attribute' => 'city',
                        'type' => DetailView::INPUT_DEPDROP,
                        'widgetOptions' => [
                            'type' => 2,
                            'data' => count($arr_cities) > 0 ? $arr_cities : [],
                            'pluginOptions' => [
                                'depends' => ['link-province'],
                                'placeholder' => '选择城市...',
                                'url' => Url::to(['/country/get-city', 'province' => 'link-province']),
                            ]
                        ],
                        'value' => $city,
                    ],
                ],
            ],
            'contact',
            [
                'attribute' => 'score',
                'type' => DetailView::INPUT_TEXTAREA,
                'options' => ['placeholder' => ''],
            ],
            'number',
            'route',
            [
                'columns' => [
                    ['attribute' => 'contact_before'],
                    ['attribute' => 'contact_now'],
                ],
            ],
            [
                'attribute' => 'history',
                'type' => DetailView::INPUT_TEXTAREA,
                'options' => ['placeholder' => ''],
            ],
            [
                'attribute' => 'remark',
                'type' => DetailView::INPUT_TEXTAREA,
                'options' => ['placeholder' => ''],
            ],
            [
                'attribute' => 'comment',
                'type' => DetailView::INPUT_TEXTAREA,
                'options' => ['placeholder' => ''],
            ],
        ];
        echo DetailView::widget([
            'model' => $model,
            'condensed' => true,
            'hover' => true,
            'mode' => 'edit',
            'panel' => [
                'heading' => '单项目信息',
                'headingOptions' => ['template' => '{title}'],
                'type' => DetailView::TYPE_INFO,
                'footer' => '<span class="glyphicon glyphicon-pencil"></span>',
                'footerOptions' => ['class' => 'panel-heading', 'tag' => 'h4', 'template' => '{buttons}{title}']
            ],
            'formOptions' => ['options' => ['data-pjax' => true],],
            'hideIfEmpty' => false,//如果有空字段则隐藏
            'buttons1' => '{update}',
            'buttons2' => '{view} {reset} {save}',
            'updateOptions' => ['label' => '<span class="btn btn-info">编辑</span>'],
            'viewOptions' => ['label' => '<span class="btn btn-info">查看</span>'],
            'saveOptions' => ['label' => $model->id == '' ? '<span class="btn btn-info">保存</span>' : (($model->id && $model->owner == Yii::$app->user->id) ? '<span class="btn btn-info">保存</span>' : '')],
            'resetOptions' => ['label' => '<span class="btn btn-info">重置</span>'],
            'attributes' => $attributes,
        ]);
        ?>
    </div>
</div>
